// miniprogram/pages/bmrs/bmrs.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dishiList:['济南','滨州','德州','东营','菏泽','济宁','聊城','临沂','青岛','日照','泰安','威海','潍坊','烟台','枣庄','淄博'],
    page:134
  },

  //点击选择-3级联动
  choisedishi() {
    var that = this;
    that.setData({
      binddishi: 1
    });
  },
  //点击选择-3级联动
  setdishi(e) {
    var that = this;
    console.log(e.currentTarget.dataset.dishi)
    that.setData({
      dishi: e.currentTarget.dataset.dishi,
      binddishi: !1
    })
  },

  closeselect() {
    var that = this;
    that.setData({
      binddishi: !1
    })
  },
  //个人信息查询提交
  submit() {
    var that = this;
    var phone = wx.getStorageSync('mskqcxphone')
    if (phone) {
      if (that.data.dishi) {
        wx.request({ //发送请求
          url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=43167&callback=?', //接收url
          data: {
            phone: phone,
            limits: 500,
            dishi: that.data.dishi
          }, //接收参数
          success(res) {
           
            var jsonStr = res.data;
            jsonStr = jsonStr.replace("(", "");
            jsonStr = jsonStr.replace(")", "");
            if (typeof jsonStr != 'object') {
              jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
              var theJson = JSON.parse(jsonStr);
            }
            console.log(theJson)
            that.setData({
              lists: theJson.lists
            })
            wx.pageScrollTo({
              scrollTop: 500,
              duration: 600
            });

          }
        })
      } else {
        wx.showToast({
          title: '请完整填写信息',
          duration: 2000,
          icon: 'none'
        })
      }

    } else {
      wx.showToast({
        title: '请先登录',
        duration: 2000,
        icon: 'none'
      })
      that.setData({
        fixed: 1
      })
    }
  },
  getPhoneNumber(e) {
    var that = this;
    var fenxiao = that.data.area;
    var geneal = that.data.geneal;
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      wx.setStorageSync('mskqcxphone', res.result)
      console.log(res.result)
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/register?actid=43167&callback=?', //接收url
        data: {
          phone: res.result,
          fenxiao: fenxiao,
          geneal: geneal,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          that.setData({
            fixed: !1
          })
        }
      })

      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId: 32,
          mobile: res.result,
          areaCode: that.data.area,
          agent: that.data.geneal,
          pageId: that.data.page
        },
        success: res => {
          console.log(res);
        }
      })
    }).catch(err => {
      console.error(err);
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent
    })
    if (options.page) {
      that.setData({
        page: options.page
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})